<?php

// $Id: legacy_and_missing.inc,v 1.1.2.7 2008/07/08 21:55:26 sicjoy Exp $

####################################################
# LEGACY functions definitions
####################################################

#global $user;if ($user==1) {
#drupal_set_message("H: ". $_SERVER['SCRIPT_NAME']);
#drupal_set_message("H: ". arg(0));
#}

drigg_legacy('drigg_embedded_contents', 'drigg_embed_contents');
drigg_legacy('theme_drigg_sections', 'drigg_ui_sections');
drigg_legacy('drigg_get_view_type_menu', 'drigg_ui_type_menu');
drigg_legacy('drigg_get_order_menu', 'drigg_ui_order_menu');
drigg_legacy('drigg_get_article_menu', 'drigg_ui_article_menu');
drigg_legacy('drigg_get_submit_button', 'drigg_ui_submit_button');
drigg_legacy('drigg_related_links_get_html', 'drigg_rl_related_links_get_html');
drigg_legacy('drigg_get_promote_string', 'drigg_promoted_string');
drigg_legacy('drigg_get_created_string', 'drigg_created_string');

#######################################################
# Warning stubs if a theme calls an undefined function
#######################################################

/* This "if" is a serious hack to prevent the situation where those functions
 * defined here, and then a module is loaded -- and bang! THe "real" module
 * cannot be loaded anymore. This works because update.php doesn't need any
 * elements from the standard theme, AND admin/build/modules/list/confirm
 * doesn't actually show anything. So, if the theme uses drigg_ui_sections,
 * and drigg_ui is not loaded, things don't go wrong anyway.
 */
if (!preg_match('|/update.php$|', $_SERVER['SCRIPT_NAME']) && 
      !(arg(0) == 'admin' && 
          arg(1) == 'build' && 
          arg(2) == 'modules' && 
          arg(3) == 'list' && 
          arg(4) == 'confirm' 
      )
  ) {
  drigg_module_missing('drigg_embed', 'drigg_embed_contents');
  drigg_module_missing('drigg_ui', 'drigg_ui_sections');
  drigg_module_missing('drigg_ui', 'drigg_ui_type_menu');
  drigg_module_missing('drigg_ui', 'drigg_ui_order_menu');
  drigg_module_missing('drigg_ui', 'drigg_ui_article_menu');
  drigg_module_missing('drigg_ui', 'drigg_ui_submit_button');
  drigg_module_missing('drigg_rl', 'drigg_rl_related_links_get_html');
}


####################################################
# Output functions
####################################################
function drigg_legacy_msg($before, $after) {
  drigg_admin_msg(t("The function !before is now actually called !after. Please update your theme accordingly!", array('!before' => $before, '!after' => $after)));
}
function drigg_module_missing_msg($module, $function) {
  drigg_admin_msg(t("You need to enable the module !module in order to use the function !function()!", array('!module' => $module, '!function' => $function)));
}

####################################################
# STUB functions
# These are generated using eval()
####################################################
function drigg_legacy($from, $to) {

eval(
"  
  function $from() {
    \$args=func_get_args();
    drigg_legacy_msg($from, $to);
    return call_user_func_array('$to', \$args);
  }

");

}

function drigg_module_missing($module, $function) {
  eval(
"
if (!module_exists('$module') && !function_exists('$function')) {
  function $function() {
    drigg_module_missing_msg('$module', '$function');
    return;
  }
}
");

}
